<template>
  <div>
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="dateRange" label="报告日期">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item name="code" label="检验大类" class="w-72">
          <a-select v-model:value="formState.code" placeholder="请选择" allow-clear>
            <a-select-option v-for="item in categoryList" :key="item" :value="item.categroyCode">{{ item.categroyName }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="mb-3">
        <BaseExport
          type="检验"
          name="检验大类工作量统计"
          code="001155"
          :search-params="{
            stdate: formState.dateRange?.[0],
            eddate: formState.dateRange?.[1],
            code: formState?.code
          }"
          >导出</BaseExport
        >
      </div>
      <BaseTable :loading="loading" column-code="001155" fill :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import dayjs from 'dayjs'
import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'

const categoryList = ref([])
const formRef = ref(null)
const formState = ref({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})

const getCategoryList = async () => {
  const { code, data, msg } = await post('/lis/InstrumentType/getLisCategroyList', { pageNum: 1, pageSize: 999 })
  if (code !== 0) return message.error(msg)
  categoryList.value = data
}

const { loading, pagination, getData, tableData } = useTable({
  url: '/lis/LisRecord/getLisCategoryStatisticsList',
  immediate: true,
  formatParams: () => {
    return {
      stdate: formState.value.dateRange?.[0],
      eddate: formState.value.dateRange?.[1],
      code: formState.value?.code
    }
  }
})

onMounted(() => {
  getCategoryList()
})
</script>
